package com.example.controller.login;

import com.example.bean.login.TUserInfo;
import com.example.config.MD5;
import com.example.service.login.LoginService;
import com.example.utils.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/userlogin")
public class LoginController {
    @Autowired
    LoginService loginService;

    @PostMapping("/login")
    public Results loginUser(@RequestBody TUserInfo tuser){
        System.out.println("接收到的登录者信息："+tuser);
        String newPassword = MD5.inputPassToFormPass(tuser.getUserPassword());
        System.out.println("新密码："+newPassword);
        tuser.setUserPassword(newPassword);
        TUserInfo user = loginService.loginUser(tuser);
        return new Results().data("user",user);
    }

    @PostMapping("/editPassword")
    public Results editPassword(@RequestBody TUserInfo user){
        String password = MD5.inputPassToFormPass(user.getUserPassword());
        System.out.println("修改新密码："+password);
        user.setUserPassword(password);
        return new Results().code(loginService.editPassword(user));
    }
}
